package com.yidu.menuProject.action;

     

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yidu.menuProject.action.vo.EhyModuleVo;
import com.yidu.menuProject.common.Tools;
import com.yidu.menuProject.model.EhyModuleModel;
import com.yidu.menuProject.model.EhyRoleModuleModel;
import com.yidu.menuProject.service.EhyModuleService;


/**
 * 						_oo0oo_
 *					   o8888888o
 *					   88" . "88
 *					   (| -_- |)
 *					   0\  =  /0
 *					 ___/`---'\___
 *				   .' \\|     |// '.
 *				  / \\|||  :  |||// \
 *				 / _||||| -:- |||||- \
 *				|   | \\\  -  /// |   |
 *				| \_|  ''\---/''  |_/ |
 *				\  .-\__  '-'  ___/-. /
 *     		  ___'. .'  /--.--\  `. .'___
 *	 	   ."" '<  `.___\_<|>_/___.' >' "".
 *	 	  | | :  `- \`.;`\ _ /`;.`/ - ` : | |
 *	 	  \  \ `_.   \_ __\ /__ _/   .-` /  /
 *	  =====`-.____`.___ \_____/___.-`___.-'=====
 * 	   				    `=---='
 *
 *
 *	  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *                  佛祖镇楼                  BUG辟易
 *          佛曰:
 *                  写字楼里写字间，写字间里程序员；
 *                  程序人员写程序，又拿程序换酒钱。
 *                  酒醒只在网上坐，酒醉还来网下眠；
 *                  酒醉酒醒日复日，网上网下年复年。
 *                  但愿老死电脑间，不愿鞠躬老板前；
 *                  奔驰宝马贵者趣，公交自行程序员。
 *                  别人笑我忒疯癫，我笑自己命太贱；
 *                  不见满街漂亮妹，哪个归得程序员？
 *                  
 * */      

@Controller
@RequestMapping("/moduleAction")
public class EhyModuleAction  {
	@Resource
	private EhyModuleService ehyModuleService ; 
	@Transactional(readOnly=false)
	
	/**
	 * 查询所有用户
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/showList")
	public  Map<String, Object>  showList(EhyModuleVo vo,int page,int limit) {
		EhyModuleVo mod = new EhyModuleVo();
		vo.setNowpage(page);
		vo.setRows(limit);
		List<EhyModuleModel> list = ehyModuleService.selectAll(vo);
		Integer count = ehyModuleService.selectCount(mod);
		Map<String, Object> map=new HashMap<>();
		map.put("code", 0);
		map.put("msg", null);
		map.put("count", count);
		map.put("data", list);
	return map;
		
	}
	
	
	@ResponseBody
	@RequestMapping("/showModule")
	public  List<EhyModuleModel>  showModule(EhyModuleVo vo) {
		
		List<EhyModuleModel> list = ehyModuleService.selectModule(vo);
		
		return list;
		
	}
	
	@ResponseBody
	@RequestMapping("/selectModule")
	public  List<EhyRoleModuleModel>  selectModule(String roleId) {
		
		List<EhyRoleModuleModel> list = ehyModuleService.selectRoleModule(roleId);
		
		return list;
		
	}
	
	
	/**
	 * 增加或修改
	 * @throws IOException 
	 */
	@ResponseBody
	@RequestMapping("/updateModule")
	public String updateModule(EhyModuleVo vo) {
		ehyModuleService.updateByPrimaryKeySelective(vo);
		vo = new EhyModuleVo();
		return "redirect:/pages/pages_xc/ModuleList.html";
		
		
	}
	
	@RequestMapping("/addModule")
	public String addModule(EhyModuleVo vo){
		vo.setModId(Tools.getStringRandom(10));
		vo.setIsva(3);
		ehyModuleService.insertSelective(vo);
		vo = new EhyModuleVo();
		return "redirect:/pages/pages_xc/ModuleList.html";
		
	}
	/**
	 * 删除用户
	 * @return
	 * @throws IOException 
	 */
	@ResponseBody
	@RequestMapping("/delete")
	public String delete(String modId){
		 System.out.println("==========================");
		 ehyModuleService.deleteByPrimaryKey(modId);
		
		return "pages_xc/ModuleList" ;
	}
	
	
	
	
}
